home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / psion / beepoff2.opl < prev    next >
Text File  |  1995-03-31  |  4KB  |  201 lines

  1. rem BeepOff2 
  2. rem Original by David Wood 
  3. rem Options by jezar@cix 
  4.  
  5. PROC beepoff2: 
  6.   global timh%,timstat% 
  7.   global k%(2),kstat% 
  8.   global bon%,boff%,hotk%,dapp$(15) 
  9.   local timoff% 
  10.  
  11.   gBorder 0 
  12.   if options%:=0 
  13.     stop 
  14.   endif 
  15.  
  16.   win2frnt:("sys$shll.*") 
  17.   Print 
  18.   Print "  BeepOff2 is running..." 
  19.   gBorder 0 
  20.   busy chr$(2)+"-Esc to stop" 
  21.   call($138b)  rem GenMarkNonActive 
  22.   ioopen(timh%,"TIM:",-1) 
  23.   if (call($c58d,$2003,$e08) and $ff)  rem wCaptureKey 
  24.     alert("Couldn't capture off key") 
  25.     stop 
  26.   endif 
  27.   if hotk% 
  28.     call($458d,hotk%,$404,0,0,0) 
  29.   endif 
  30.    
  31.   quekey: 
  32.   quetim: 
  33.   while 1 
  34.     iowait 
  35.     if kstat%<>-46   rem Key was pressed 
  36.       if k%(1)=$2003 
  37.         DoOff: 
  38.       elseif k%(1)=hotk% and hotk% 
  39.           win2frnt:("sys$shll.*") 
  40.       endif 
  41.       quekey: 
  42.     elseif timstat%<>-46  rem Timer expired 
  43.       timoff%=timelft%: 
  44.       if timoff%>=0 and timoff%<=3 
  45.         DoOff: 
  46.       endif 
  47.       quetim: 
  48.     else 
  49.       alert("Stray signal","Programming error") 
  50.       stop 
  51.     endif 
  52.   endwh 
  53. ENDP 
  54.  
  55. PROC quekey: 
  56.   keya(kstat%,k%(1)) 
  57. ENDP 
  58.  
  59. PROC quetim: 
  60. rem Queue timer so it goes off 2 seconds before auto-off 
  61. rem or after another 12 seconds, whichever is sooner 
  62.   local t&,t% 
  63.   t%=timelft%: 
  64.   if t%<0 
  65.     t%=12 
  66.   elseif t%>12 
  67.     t%=12 
  68.   elseif t%>2 
  69.     t%=t%-2 
  70.   endif 
  71.   t&=int(t%)*10 
  72.   ioa(timh%,1,timstat%,t&,#0) 
  73. ENDP 
  74.  
  75. PROC timelft%: 
  76. rem returns seconds to go before autoswitchoff 
  77. rem returns -1 if not going to autoswitchoff 
  78.   local gooff%,timeoff%   rem keep together 
  79.   if notifm%: 
  80.     return -1 
  81.   endif 
  82.   call($078b,0,4,0,$40a,addr(gooff%)) rem GenGetOsData 
  83.   if gooff%<0 
  84.     return -1 
  85.   else 
  86.     return(timeoff%) 
  87.   endif 
  88. ENDP 
  89.  
  90. PROC notifm%: 
  91. rem returns TRUE if won't switch off, because "on external power" 
  92.   if (peekb(peekw($18)+13) and $f) <2 
  93.     return 0  rem not S3a 
  94.   elseif (call($388b) and $ff) <>1  rem GenGetAutoMains 
  95.     return 0 
  96.   else 
  97.     return(mainsin%:) 
  98.   endif 
  99. ENDP 
  100.  
  101. PROC mainsin%: 
  102. rem returns TRUE if mains is plugged in 
  103.   local esup%(3) 
  104.   call($118e,addr(esup%(1)))  rem HwGetSupplyStatus 
  105.   return esup%(3) 
  106. ENDP 
  107.  
  108. PROC dobeep: 
  109.   call($328b)  rem GenTickle - reset inactivity counter 
  110.   rem prevents switching off half way through the beeps 
  111.   beep 1,300 
  112.   beep 1,400 
  113.   beep 1,500 
  114. ENDP 
  115.  
  116. PROC win2frnt:(proc$) 
  117.     local ax%,bx%,cx%,dx%,si%,di% 
  118.     local name$(14) 
  119.      
  120.     name$=proc$+chr$(0) 
  121.     ax%=$0100 
  122.     bx%=Addr(name$)+1 
  123.     Os($88,Addr(ax%)) 
  124.     Call($198d,0,ax%,0,0,0) 
  125.     Key 
  126. ENDP 
  127.  
  128.  
  129. PROC options%: 
  130.     local retval%,hot%,dapp% 
  131.      
  132.     rem Dialog defaults here: 
  133.     bon%=2  rem beeps off 
  134.     boff%=2 
  135.     dapp%=6 rem my preference 
  136.     hot%=2  rem cntl-z 
  137.      
  138.     dInit 
  139.     dText "","BeepOff2 options:",$202 
  140.     dChoice bon%,"Beep at on","Yes,No" 
  141.     dChoice boff%,"Beep at off","Yes,No" 
  142.     dChoice hot%,"System hotkey","None,Cntl-z,Cntl-x" 
  143.     dChoice dapp%,"Default application","None,System,Data,Word,Agenda,Time,World,Calc" 
  144.     retval%=dialog 
  145.      
  146.     if hot%=2 
  147.         hotk%=26 
  148.     elseif hot%=3 
  149.         hotk%=24 
  150.     endif 
  151.      
  152.     if dapp%=2 
  153.         dapp$="sys$shll.*" 
  154.     elseif dapp%=3 
  155.         dapp$="Data.*" 
  156.     elseif dapp%=4 
  157.         dapp$="Word.*" 
  158.     elseif dapp%=5 
  159.         dapp$="Agenda.*" 
  160.     elseif dapp%=6 
  161.         dapp$="Time.*" 
  162.     elseif dapp%=7 
  163.         dapp$="World.*" 
  164.     elseif dapp%=8 
  165.         dapp$="Calc.*" 
  166.     endif 
  167.      
  168.     bon%=2-bon% 
  169.     boff%=2-boff% 
  170.      
  171.     return retval% 
  172. ENDP 
  173.  
  174. proc DoOff: 
  175.     PreOff: 
  176.     OFF 
  177.     PostOff: 
  178. endp 
  179.  
  180. proc PreOff: 
  181.     if boff% 
  182.         dobeep: 
  183.     endif 
  184.      
  185.     rem Moving the default app to 
  186.     rem the front prior to switch 
  187.     rem off, improves performance 
  188.     rem over doing it after switch 
  189.     rem on. 
  190.     if not (dapp$="") 
  191.         win2frnt:(dapp$) 
  192.     endif 
  193. endp 
  194.  
  195. proc PostOff: 
  196.     if bon% 
  197.         dobeep: 
  198.     endif 
  199. endp 
  200.  
  201.